﻿using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Alogient.Cameleon.Sdk.UI.WebControls
{
    [DefaultProperty("Value")]
    [ToolboxData("<{0}:CMLiteral runat=server></{0}:CMLiteral>")]
    public class CMLiteral : Literal
    {
        protected int navID = NavigationController.GetNavID();
        protected string cultureCode = NavigationController.GetCultureCode();
        protected string value = null;

        [Category("Cameleon")]
        [Browsable(true)]
        public string BindField { get; set; }

        public string Value
        {
            get
            {
                if (this.value == null && this.BindField != null)
                {
                    this.value = CMServices.GetPage(this.navID, this.cultureCode).Elements[this.BindField].Value;
                }

                return this.value;
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            this.Text = this.Value;

            base.Render(writer);
        }
    }
}
